package com.jielihaofeng.chat.constants;

import java.util.Arrays;
import java.util.Objects;

/**
 * 好友关系状态枚举
 */
public enum ChatUserRelationStatusEnum {

    READY(0, "申请"),
    ALREADY(1, "好友");

    private final Integer code;
    private final String name;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    ChatUserRelationStatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过code获取枚举
     *
     * @param code 编码
     * @return 枚举
     */
    public static ChatUserRelationStatusEnum getByCode(Integer code) {
        return Arrays.stream(ChatUserRelationStatusEnum.values())
                .filter(statusEnum -> Objects.equals(statusEnum.getCode(), code))
                .findFirst()
                .orElse(null);
    }
}
